package com.myrpc.loadBalance.implement;

import com.myrpc.loadBalance.AbstractLoadBalance;
import com.myrpc.transfer.dto.RpcRequest;

import java.util.List;
import java.util.Random;

/**
 * 随机选择负载均衡算法
 * 算法原理：对列表元素进行随机选择
 */
public class RandomLoadBalance extends AbstractLoadBalance {
    @Override
    protected <T> T loadBalance(List<T> serviceList, RpcRequest rpcRequest) {
        Random random = new Random();
        return serviceList.get(random.nextInt(serviceList.size()));
    }
}
